package com.lxw.nonghe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxw.nonghe.entity.AnnualFeeStandard;
import com.lxw.nonghe.mapper.AnnualFeeStandardMapper;
import com.lxw.nonghe.service.AnnualFeeStandardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 年度缴费标准表 服务实现类
 * </p>
 *
 * @author lxw
 * @since 2025-05-14
 */
@Service
public class AnnualFeeStandardServiceImpl
        extends ServiceImpl<AnnualFeeStandardMapper, AnnualFeeStandard>
        implements AnnualFeeStandardService {

    @Override
    public Page<AnnualFeeStandard> getFeeStandardPage(
            int current, int size,
            Integer year, Byte status) {

        QueryWrapper<AnnualFeeStandard> wrapper = new QueryWrapper<>();

        // 年份精确查询
        if (year != null) {
            wrapper.eq("year", year);
        }

        // 状态精确查询
        if (status != null) {
            wrapper.eq("status", status);
        }

        // 排序，最新创建的在前面
        wrapper.orderByDesc("create_time");

        // 执行分页查询
        return this.page(new Page<>(current, size), wrapper);
    }

    // 新增条件查询实现
    @Override
    public Page<AnnualFeeStandard> queryFeeStandards(
            AnnualFeeStandard queryParam,
            int current, int size) {

        QueryWrapper<AnnualFeeStandard> wrapper = new QueryWrapper<>();

        // 年份精确查询
        if (queryParam.getYear() != null) {
            wrapper.eq("year", queryParam.getYear());
        }

        // 金额精确查询
        if (queryParam.getAmount() != null) {
            wrapper.eq("amount", queryParam.getAmount());
        }

        // 状态精确查询
        if (queryParam.getStatus() != null) {
            wrapper.eq("status", queryParam.getStatus());
        }

        // 创建时间范围查询
        if (queryParam.getCreateTime() != null) {
            wrapper.ge("create_time", queryParam.getCreateTime());
        }

        // 更新时间范围查询
        if (queryParam.getUpdateTime() != null) {
            wrapper.le("update_time", queryParam.getUpdateTime());
        }

        // 排序，最新创建的在前面
        wrapper.orderByDesc("create_time");

        // 执行分页查询
        return this.page(new Page<>(current, size), wrapper);
    }
}
